function listToTree(list) {
  var map = {},
    node,
    tree = []
  for (let i = 0; i < list.length; i++) {
    map[list[i].menuId] = list[i]
    list[i].children = []
  }
  for (let i = 0; i < list.length; i++) {
    node = list[i]
    if (node.pid !== 0) {
      map[node.pid].children.push(node)
    } else {
      tree.push(node)
    }
  }
  return tree
}

module.exports = listToTree
